package com.alibaba.citrus.cr.platform.enhance.repository.impl;

import java.util.List;

import javax.annotation.Resource;

import com.alibaba.citrus.cr.platform.enhance.repository.OperateLogQueryRepository;
import com.alibaba.lattice2.epoch.sdk.model.Result;

import com.epoch.app.crplatformenhance.domain.operatelog.model.OperateLog;
import com.epoch.app.crplatformenhance.domain.operatelog.service.OperateLogService;
import com.epoch.app.crplatformenhance.model.dto.OperateLogLoadListRequest;
import com.epoch.app.crplatformenhance.model.dto.OperateQueryInfoRequest;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Repository;

/**
 * @author: qiaojiange
 * @create: 2021/11/10
 * @Description 操作日志查询服务
 */
@Repository
public class OperateLogQueryRepositoryImpl implements OperateLogQueryRepository {
    @Resource
    private OperateLogService operateLogService;

    @Override
    public Result<List<OperateLog>> queryOperateLog(OperateQueryInfoRequest request) {
        OperateLogLoadListRequest listRequest = new OperateLogLoadListRequest();
        BeanUtils.copyProperties(request, listRequest);
        //因日志分库分表,根据id排序日志时间会错乱,改成用创建时间排序
        listRequest.setDir("gmt_create");
        listRequest.setAsc(true);
        if (request.getLimit() == null){
            listRequest.setLimit(1000);
        }
        return operateLogService.queryOperateLogByPage(listRequest);
    }
}
